<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getMaxSubstrLen(str1, str2) {
            let shorter, longer;
            if (str1.length > str2.length) {
                shorter = str2;
                longer = str1
            } else {
                shorter = str1;
                longer = str2;
            }
            for (let subLength = shorter.length; subLength > 0; subLength--) {
                for (let i = 0; i + subLength <= shorter.length; i++) {
                    let subString = shorter.substring(i, i + subLength);
                    if (longer.indexOf(subString) >= 0) {
                        return subString.length;
                    }
                }
            }
            return 0;
        }
        console.log(getMaxSubstrLen("djkabcdaaa", "labcagf"));
    </script>
</body>

</html>